#include <iostream>

using namespace std;

/*
int fib[33] = {0, 1, 1};
int main()
{
    for(int i = 3; i < 33; ++i)
        fib[i] = fib[i-1] + fib[i-2];

    int n;
    cin >> n;
    int step = fib[32];
    for(int i =  0; i < 33; ++i){
        int temp = n - fib[i];
        if(temp < 0) temp *= -1;
        step = step<temp ? step : temp;
    }
    cout << step << endl;
    return 0;
}
*/

int FibStep(int n){
    if(n <= 2) return 0;

    int left = 1, fib = 2;
    int right = 0;
    while(right < n){
        right = left + fib;   // 找第一个大于n的斐波那契数:right
        left = fib;       // 第一个小于n的斐波那契数:left
        fib = right;
    }
    return min((n-left), (right-n));
}

int main()
{
    int n;
    cin >> n;
    cout << FibStep(n);
    return 0;
}